from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-10 14:02:28.910467
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 10, Sep, 2022
Time: 14:02:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.3826
Nobs: 775.000 HQIC: -50.7150
Log likelihood: 9925.53 FPE: 7.66414e-23
AIC: -50.9229 Det(Omega_mle): 6.82892e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298507 0.054289 5.498 0.000
L1.Burgenland 0.107153 0.036144 2.965 0.003
L1.Kärnten -0.106704 0.019210 -5.555 0.000
L1.Niederösterreich 0.205783 0.075626 2.721 0.007
L1.Oberösterreich 0.113928 0.073160 1.557 0.119
L1.Salzburg 0.253386 0.038681 6.551 0.000
L1.Steiermark 0.036226 0.050431 0.718 0.473
L1.Tirol 0.106734 0.040864 2.612 0.009
L1.Vorarlberg -0.060665 0.035152 -1.726 0.084
L1.Wien 0.050264 0.065064 0.773 0.440
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058704 0.112715 0.521 0.602
L1.Burgenland -0.033600 0.075041 -0.448 0.654
L1.Kärnten 0.047530 0.039883 1.192 0.233
L1.Niederösterreich -0.177174 0.157013 -1.128 0.259
L1.Oberösterreich 0.396532 0.151895 2.611 0.009
L1.Salzburg 0.289322 0.080309 3.603 0.000
L1.Steiermark 0.106274 0.104705 1.015 0.310
L1.Tirol 0.313760 0.084841 3.698 0.000
L1.Vorarlberg 0.027356 0.072982 0.375 0.708
L1.Wien -0.021603 0.135084 -0.160 0.873
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191590 0.027879 6.872 0.000
L1.Burgenland 0.089580 0.018561 4.826 0.000
L1.Kärnten -0.008472 0.009865 -0.859 0.390
L1.Niederösterreich 0.260779 0.038836 6.715 0.000
L1.Oberösterreich 0.134025 0.037570 3.567 0.000
L1.Salzburg 0.045930 0.019864 2.312 0.021
L1.Steiermark 0.018234 0.025898 0.704 0.481
L1.Tirol 0.092976 0.020985 4.431 0.000
L1.Vorarlberg 0.058350 0.018052 3.232 0.001
L1.Wien 0.118099 0.033412 3.535 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108572 0.028379 3.826 0.000
L1.Burgenland 0.046983 0.018893 2.487 0.013
L1.Kärnten -0.015049 0.010041 -1.499 0.134
L1.Niederösterreich 0.191422 0.039532 4.842 0.000
L1.Oberösterreich 0.290152 0.038243 7.587 0.000
L1.Salzburg 0.112056 0.020220 5.542 0.000
L1.Steiermark 0.102373 0.026362 3.883 0.000
L1.Tirol 0.111076 0.021361 5.200 0.000
L1.Vorarlberg 0.069660 0.018375 3.791 0.000
L1.Wien -0.017925 0.034011 -0.527 0.598
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131014 0.051510 2.543 0.011
L1.Burgenland -0.050963 0.034294 -1.486 0.137
L1.Kärnten -0.040213 0.018226 -2.206 0.027
L1.Niederösterreich 0.170396 0.071754 2.375 0.018
L1.Oberösterreich 0.138882 0.069415 2.001 0.045
L1.Salzburg 0.287292 0.036701 7.828 0.000
L1.Steiermark 0.034473 0.047850 0.720 0.471
L1.Tirol 0.161550 0.038772 4.167 0.000
L1.Vorarlberg 0.100732 0.033353 3.020 0.003
L1.Wien 0.068732 0.061733 1.113 0.266
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056339 0.041001 1.374 0.169
L1.Burgenland 0.040402 0.027297 1.480 0.139
L1.Kärnten 0.050673 0.014508 3.493 0.000
L1.Niederösterreich 0.220974 0.057114 3.869 0.000
L1.Oberösterreich 0.283174 0.055252 5.125 0.000
L1.Salzburg 0.045603 0.029213 1.561 0.119
L1.Steiermark -0.001126 0.038087 -0.030 0.976
L1.Tirol 0.147572 0.030861 4.782 0.000
L1.Vorarlberg 0.073032 0.026548 2.751 0.006
L1.Wien 0.084140 0.049138 1.712 0.087
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180543 0.049094 3.677 0.000
L1.Burgenland -0.006494 0.032685 -0.199 0.843
L1.Kärnten -0.061296 0.017371 -3.529 0.000
L1.Niederösterreich -0.084054 0.068389 -1.229 0.219
L1.Oberösterreich 0.196206 0.066159 2.966 0.003
L1.Salzburg 0.056437 0.034980 1.613 0.107
L1.Steiermark 0.231609 0.045605 5.079 0.000
L1.Tirol 0.493640 0.036954 13.358 0.000
L1.Vorarlberg 0.048112 0.031788 1.514 0.130
L1.Wien -0.052496 0.058837 -0.892 0.372
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166393 0.056343 2.953 0.003
L1.Burgenland -0.010376 0.037511 -0.277 0.782
L1.Kärnten 0.067052 0.019936 3.363 0.001
L1.Niederösterreich 0.205872 0.078487 2.623 0.009
L1.Oberösterreich -0.070610 0.075928 -0.930 0.352
L1.Salzburg 0.211602 0.040144 5.271 0.000
L1.Steiermark 0.115475 0.052339 2.206 0.027
L1.Tirol 0.072054 0.042410 1.699 0.089
L1.Vorarlberg 0.121634 0.036482 3.334 0.001
L1.Wien 0.122517 0.067525 1.814 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357775 0.032590 10.978 0.000
L1.Burgenland 0.005245 0.021697 0.242 0.809
L1.Kärnten -0.023348 0.011532 -2.025 0.043
L1.Niederösterreich 0.214731 0.045398 4.730 0.000
L1.Oberösterreich 0.188156 0.043918 4.284 0.000
L1.Salzburg 0.046333 0.023220 1.995 0.046
L1.Steiermark -0.015709 0.030274 -0.519 0.604
L1.Tirol 0.106566 0.024531 4.344 0.000
L1.Vorarlberg 0.073540 0.021102 3.485 0.000
L1.Wien 0.048096 0.039058 1.231 0.218
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040194 0.148484 0.192351 0.156837 0.124523 0.112813 0.065993 0.222248
Kärnten 0.040194 1.000000 -0.003902 0.132066 0.041674 0.095691 0.430471 -0.052320 0.100210
Niederösterreich 0.148484 -0.003902 1.000000 0.337174 0.151714 0.298353 0.108206 0.183432 0.323559
Oberösterreich 0.192351 0.132066 0.337174 1.000000 0.227963 0.330216 0.172507 0.168066 0.265130
Salzburg 0.156837 0.041674 0.151714 0.227963 1.000000 0.147387 0.122856 0.147275 0.133429
Steiermark 0.124523 0.095691 0.298353 0.330216 0.147387 1.000000 0.151621 0.138640 0.079584
Tirol 0.112813 0.430471 0.108206 0.172507 0.122856 0.151621 1.000000 0.115085 0.153498
Vorarlberg 0.065993 -0.052320 0.183432 0.168066 0.147275 0.138640 0.115085 1.000000 0.006756
Wien 0.222248 0.100210 0.323559 0.265130 0.133429 0.079584 0.153498 0.006756 1.000000